package com.deercrowing.takeaway.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.deercrowing.takeaway.vo.DishesPageVO;
import com.deercrowing.takeaway.vo.DishesVO;
import org.apache.ibatis.annotations.Mapper;
import com.deercrowing.takeaway.entity.DishesEntity;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;


/**
 * 菜品表(Dishes)表数据库访问层
 *
 * @author guoyongxiang
 * @since 2024-07-11 10:50:59
 */
@Mapper
public interface DishesMapper extends BaseMapper<DishesEntity> {

    /**
     * 搜索所有菜品信息
     *
     * @return
     */
    @Select("select * from tb_dishes")
    List<DishesEntity> selectList();

    /**
     * 变更菜品起售\禁用状态
     *
     * @param status
     * @param id
     */
    @Update("update tb_dishes set status = #{status} where id = #{id}")
    void updateByStatus(Short status, Integer id);

    /**
     * 根据分类ID统计数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from tb_dishes where category_id = #{categoryId}")
    int countIndex(Integer categoryId);

    /**
     * 根据搜索条件搜索信息
     *
     * @param dishesPageVO
     * @return
     */
    List<DishesEntity> selectListByCondition(DishesPageVO dishesPageVO);

    /**
     * 统计菜品起售和禁售的数量
     *
     * @param dataMap
     * @return
     */
    Integer countByMap(Map<String,Object> dataMap);

    /**
     * 根据分类ID搜索菜品列表
     *
     * @param category_id
     * @return
     */
    List<DishesEntity> selectListByCategory(Short category_id);

    /**
     * 根据菜品名称搜索
     *
     * @param name
     * @return
     */
    @Select("select id from tb_dishes where name = #{name}")
    Integer selectIdByName(String name);

    /**
     * 搜索套餐中绑定的菜品信息
     *
     * @param id
     * @return
     */
    @Select("select a.* from tb_dishes a ,tb_setmeal_dish b where a.id = b.dish_id and b.setmeal_id = #{id}")
    List<DishesEntity> selectListBySetmealId(Integer id);

    /**
     * 根据条件搜索菜品数量
     *
     * @param dishesPageVO
     * @return
     */
    Integer countDishNum(DishesPageVO dishesPageVO);
}

